using System;
using System.Collections.Generic;
using System.Text;
using Fieldbook.Entities;
using Fieldbook.DAL;
using Fieldbook.Common;

namespace Fieldbook.Business
{
    public static class PlantSpecieController
    {
        #region PlantSpecies
        public static List<PlantSpecie> LoadAllPlantSpecies()
        {
            List<PlantSpecie> res = null;
            try
            {
                res = PlantSpecieDAO.LoadAllPlantSpecies();
            }
            catch (Exception ex)
            {
                LogManager.LogException("Error getting plant species", ex);
            }
            return res;
        }

        public static bool InsertPlantSpecie(PlantSpecie specie)
        {
            bool res = false;
            try
            {
                res = PlantSpecieDAO.InsertPlantSpecie(specie);
            }
            catch (Exception ex)
            {
                LogManager.LogException("Error inserting plant specie", ex);
            }
            return res;
        }

        #endregion

        #region Field plant species
        public static List<FieldPlantSpecie> LoadHouseHoldSpecies(long userID)
        {
            List<FieldPlantSpecie> res = null;
            try
            {
                res = FieldPlantSpecieDAO.LoadHouseHoldPlantSpecies(userID);
            }
            catch (Exception ex)
            {
                LogManager.LogException("Error retreiving plant species for household", ex);
            }
            return res;
        }

        public static List<FieldPlantSpecie> LoadFieldSpecies(long userID, long fieldID)
        {
            List<FieldPlantSpecie> res = null;
            try
            {
                res = FieldPlantSpecieDAO.LoadFieldPlantSpecies(userID, fieldID, "ORDER BY FPS.SPECIESTARTDATE DESC");
            }
            catch (Exception ex)
            {
                LogManager.LogException("Error retreiving plant species for field", ex);
            }
            return res;
        }

        public static bool InsertFieldPlantSpecie(FieldPlantSpecie specie)
        {
            bool res = false;
            try
            {
                res = FieldPlantSpecieDAO.InsertFieldPlantSpecie(specie);   
            }
            catch (Exception ex)
            {
                LogManager.LogException("Error inserting plant species for field", ex);
            }
            return res;
        }
        #endregion
    }
}
